﻿using Framework;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Experimental.U2D.Animation;
using UnityEngine.InputSystem.UI;

namespace Game
{
    public class Starter : MonoBehaviour
    {
        public void Awake()
        {
            DontDestroyOnLoad(Camera.main);
            DontDestroyOnLoad(gameObject);
            InitInputModule();
            gameObject.AddComponent<GameUISystem>();
            gameObject.AddComponent<BTreeScheduler>();
            gameObject.AddComponent<Scheduler>();
            gameObject.AddComponent<TouchSystem>();
        }

        public void Start()
        {
            DontDestroyOnLoad(GameObject.Find("MainCamera"));
            StartBTreeBuilder builder = new StartBTreeBuilder(new StartBTreeContext());
            BehaviorTree<StartBTreeContext> tree = builder.Build();
            tree.Ended += OnStartCompleted;
            BTreeScheduler.Instance.StartTree(builder.Build());
        }

        private void InitInputModule()
        {
            InputSystemUIInputModule inputModule = gameObject.AddComponent<InputSystemUIInputModule>();
            // to do something
        }

        private void OnStartCompleted(StartBTreeContext context)
        {
            SceneSystem.Instance.LoadScene("quest");
        }
    }
}